An interface for specialized brush renderers, which implement brush rendering. More...
#include <kanzi/core.ui/graphics2d/brush_renderer.hpp>
Public Types | |
enum | RenderMode { RenderModeNone , RenderModeContent , RenderModeNoContent } |
Enum signifying currently selected render mode. More... | |
Public Member Functions | |
MaterialSharedPtr | acquireErrorMaterial () |
Acquires an error material for rendering. | |
void | attachMaterial (MaterialSharedPtr material) |
Attaches a custom material. | |
void | bind (Renderer3D &renderer) |
Binds a brush renderer for rendering. | |
void | bind (Renderer3D &renderer, PropertyObject *object) |
Binds a brush renderer for rendering. | |
void | draw (Renderer &renderer, const Geometry &quad, const Matrix3x3 &transform) |
Overload for drawing a brush using a given quad. | |
void | draw (Renderer &renderer, const Geometry &quad, const Matrix4x4 &transform) |
Draws a brush using a given quad. | |
optional< int > | getBlendModeOverride () const |
Gets the blend mode override value. | |
int | getBlendModeValue () const |
Gets the last used blend mode value. | |
Brush * | getBrush () const |
Gets the brush for which Kanzi created this brush renderer. | |
TextureSharedPtr | getContentTexture () const |
Gets the content texture used by the brush renderer. | |
MaterialSharedPtr | getMaterial () const |
Gets the currently set material for the renderer. | |
Node * | getNode () const |
Gets the attached node. | |
bool | getOpaquenessHint () const |
Gets the opaqueness hint value. | |
unsigned int | getPropertyChangeCounter () const |
Gets the brush property change counter. | |
RenderMode | getRenderMode () const |
Gets the currently selected render mode. | |
float | getRenderOpacity () const |
Gets the render opacity. | |
GlRenderState & | getRenderState () |
Gets the internal render state. | |
void | invalidateRenderValues () |
Invalidates all render values. | |
bool | isOpaque () const |
Indicates whether the rendered brush is opaque. | |
bool | isRenderable () const |
Indicates whether a brush is in a renderable state. | |
void | restoreResources () |
Restores resources after sleep. | |
void | setBlendModeOverride (optional< int > blendMode) |
Sets the blend mode override value. | |
void | setContentTexture (TextureSharedPtr texture) |
Sets the content texture for the brush renderer. | |
void | setOpaquenessHint (bool value) |
Sets the opaqueness hint. | |
void | setRenderOpacity (float opacity) |
Sets the render opacity to use for the next attach. | |
void | updateRender () |
Prepares a brush for rendering. | |
virtual | ~BrushRenderer ()=default |
Destructor. | |
Protected Member Functions | |
virtual bool | bindOverride (Renderer3D &renderer, PropertyObject *object) |
BrushRenderer-specific bind implementation. | |
BrushRenderer (Brush *brush, Node *node) | |
Constructor. | |
virtual void | drawOverride (Renderer &renderer, const Geometry &geometry, const Matrix4x4 &transform)=0 |
Draws geometry using the brush. | |
virtual bool | isChangeCounterSame () |
Checks whether the property change counter matches that of the brush. | |
virtual void | restoreResourcesOverride () |
BrushRenderer-specific restore resources implementation. | |
virtual void | setContentTextureOverride (TextureSharedPtr texture) |
BrushRenderer-specific update of the content texture. | |
void | setRenderMode (RenderMode selection) |
Sets the render mode. | |
virtual void | updateChangeCounter () |
Updates the property change counter to match the counter value from the brush. | |
virtual void | updateRenderOverride ()=0 |
BrushRenderer-specific opacity override implementation. | |
Protected Attributes | |
Brush * | m_brush |
Brush attached to. | |
unsigned int | m_brushPropertyChangeCounter |
Property change counter to track brush. | |
TextureSharedPtr | m_contentTexture |
Content texture provided to the brush renderer from outside. For example, from Node2D. | |
GlRenderState::HandleType | m_contentTextureHandle |
Render value handle. | |
bool | m_isRenderable |
Indicates whether the last bind() call was successful and the brush can be rendered. | |
Node * | m_node |
Node attached to. | |
RenderMode | m_renderMode |
Currently used render mode (or none if not selected). | |
float | m_renderOpacity |
Render opacity provided to the brush renderer from outside. For example, from Node2D. | |
GlRenderState::HandleType | m_renderOpacityHandle |
Render value handle. | |
GlRenderState | m_renderState |
Contained render state. | |
GlRenderValueBinding | m_renderValueBinding |
Property binding handler. | |
An interface for specialized brush renderers, which implement brush rendering.
You can use the BrushRenderer to render a brush manually.
To render a brush manually:
Call setContentTexture() to set the content texture for the brush renderer.
You must do this before you call updateRender().
Call updateRender() to prepare the brush for rendering.
You must call updateRender() once after you set the content texture and before you bind the brush renderer for rendering. You do not need to call this function every time after changing the content texture, unless you change the content texture to or from nullptr.
Call setRenderOpacity() to set the render opacity.
You can do this before or after calling updateRender().
(Optional) If you want to set the blend mode as determined by layouting, call setBlendModeOverride().
This function takes precedence over the blend mode that the renderer reads from the brush.
(Optional) If you want to indicate that a node can be rendered using opaque blend mode, call setOpaquenessHint().
For example, this happens when a node is rendered as the bottom-most element in a framebuffer.
To draw with the brush, call draw().
After you call bind(), you can call draw() multiple times for different geometries and transformations.
For example:
|
virtualdefault |
Destructor.
Constructor.
node | The node to which to attach the renderer. |
brush | The brush to which to attach the renderer. |
|
inline |
Prepares a brush for rendering.
Called from Node2D::updateRender(), which calls NodeVisual2D::updateRender(). Kanzi calls this function during layout.
Call this function after the brush material or attached nodes change. Unlike bind(), you do not need to call updateRender() every frame before draw().
If the render mode of a brush does not change, implementations of this function do nothing.
blendMode
parameter. forceOpaque
parameter. blendMode
and translucencyHint
parameters.
|
inline |
Binds a brush renderer for rendering.
You must call this function before you call draw(). This function sets the renderable flag that you can query with isRenderable().
renderer | The renderer to use. |
object | The object from which to fetch properties. |
|
inline |
Binds a brush renderer for rendering.
You must call this function before you call draw(). This function sets the renderable flag that you can query with isRenderable().
renderer | Renderer to use. |
void kanzi::BrushRenderer::draw | ( | Renderer & | renderer, |
const Geometry & | quad, | ||
const Matrix4x4 & | transform ) |
Draws a brush using a given quad.
renderer | Renderer to use. |
quad | Quad to draw. |
transform | The transform as a 4x4 matrix to use. |
|
inline |
Overload for drawing a brush using a given quad.
renderer | Renderer to use. |
quad | Quad to draw. |
transform | The transform as a 3x3 matrix to use. |
|
inline |
Restores resources after sleep.
|
inline |
Gets the brush for which Kanzi created this brush renderer.
|
inline |
Gets the internal render state.
|
inline |
Invalidates all render values.
MaterialSharedPtr kanzi::BrushRenderer::acquireErrorMaterial | ( | ) |
Acquires an error material for rendering.
Kanzi uses this function internally when the assigned material is not applicable.
Gets the brush property change counter.
|
inline |
Gets the render opacity.
Sets the render opacity to use for the next attach.
opacity | New render opacity. |
|
inline |
Gets the content texture used by the brush renderer.
|
inline |
Sets the content texture for the brush renderer.
texture | The content texture. |
|
inline |
Gets the currently selected render mode.
|
inline |
Indicates whether a brush is in a renderable state.
To set the renderable flag, call bind().
MaterialSharedPtr kanzi::BrushRenderer::getMaterial | ( | ) | const |
Gets the currently set material for the renderer.
int kanzi::BrushRenderer::getBlendModeValue | ( | ) | const |
Gets the last used blend mode value.
This function is intended for tests.
Sets the blend mode override value.
This is the blend mode as determined by layouting. Calling this function has precedence over the blend mode read from brush or material.
blendMode | Blend mode. |
|
inline |
Gets the blend mode override value.
This function is intended for tests.
Sets the opaqueness hint.
This hint indicates whether a node can be rendered using opaque blend mode. For example, this happens when a node is rendered as the bottom-most element in a framebuffer.
value | Opaqueness hint value. |
|
inline |
Gets the opaqueness hint value.
This function is intended for tests.
|
inline |
Indicates whether the rendered brush is opaque.
void kanzi::BrushRenderer::attachMaterial | ( | MaterialSharedPtr | material | ) |
Attaches a custom material.
This function internally calls BrushRenderer::attachMaterial().
material | The material to attach. |
|
protectedpure virtual |
Draws geometry using the brush.
To be implemented by specific brush implementations.
renderer | Renderer to use. |
geometry | Quad to draw. |
transform | Transform to use. |
Implemented in kanzi::ColorBrushRenderer, kanzi::ContentBrushRenderer, kanzi::MaterialBrushRenderer, and kanzi::TextureBrushRenderer.
|
protectedvirtual |
BrushRenderer-specific bind implementation.
renderer | Renderer to use. |
object | The object from which to fetch properties. |
object
. Reimplemented in kanzi::ColorBrushRenderer, kanzi::ContentBrushRenderer, and kanzi::TextureBrushRenderer.
BrushRenderer-specific opacity override implementation.
blendMode
parameter. forceOpaque
parameter. blendMode
and translucencyHint
parameters. Implemented in kanzi::ColorBrushRenderer, kanzi::ContentBrushRenderer, kanzi::MaterialBrushRenderer, and kanzi::TextureBrushRenderer.
BrushRenderer-specific restore resources implementation.
|
inlineprotectedvirtual |
BrushRenderer-specific update of the content texture.
texture | New renderer texture. |
|
inlineprotected |
Sets the render mode.
selection | The render mode to set. |
Checks whether the property change counter matches that of the brush.
Reimplemented in kanzi::MaterialBrushRenderer.
Updates the property change counter to match the counter value from the brush.
Reimplemented in kanzi::MaterialBrushRenderer.
|
protected |
Brush attached to.
|
protected |
Currently used render mode (or none if not selected).
|
protected |
Contained render state.
|
protected |
Property binding handler.
|
protected |
Render value handle.
|
protected |
Render value handle.
|
protected |
Content texture provided to the brush renderer from outside. For example, from Node2D.
|
protected |
Render opacity provided to the brush renderer from outside. For example, from Node2D.
Property change counter to track brush.
|
protected |
Indicates whether the last bind() call was successful and the brush can be rendered.
The return value from bindOverride() is written here.